package com.yinda.dt.produce.app;

import android.util.Log;

import com.mingle.widget.ShapeLoadingDialog;
import com.xcgame.oh.OkHttp;
import com.xcgame.oh.UploadResponseCallback;
import com.yinda.dt.produce.utils.DesUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * Created by Administrator on 2017/3/30.
 */

public class MyUploadResponseCallback extends UploadResponseCallback {

    private ShapeLoadingDialog loadingDialog;

    public MyUploadResponseCallback() {
    }

    public MyUploadResponseCallback(ShapeLoadingDialog loadingDialog) {
        this.loadingDialog = loadingDialog;
    }

    @Override
    public void onStart() {
        super.onStart();
        if (loadingDialog != null) {
            loadingDialog.show();
        }
    }

    @Override
    public void onFinish() {
        super.onFinish();
        if (loadingDialog != null) {
            loadingDialog.dismiss();
        }
    }

    @Override
    public final void onSuccess(String responseString) {
        try {
            JSONObject jsonResponse = new JSONObject(responseString);
            String jsonString = URLDecoder.decode(new DesUtil("dtsbsbdsb", true).decode(jsonResponse.getString("result")), "utf-8");
            JSONObject jsonResult = new JSONObject(jsonString);
            onSuccess(jsonResult);
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void onSuccess(JSONObject jsonResult) {
        if (OkHttp.isPrintLog) {
            Log.d(OkHttp.TAG, "文件上传成功：" + jsonResult.toString());
        }
    }
}
